<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <meta name="description" content="API docs for the paint method from the TexturedLinePainter class, for the Dart programming language.">
  <title>paint method - TexturedLinePainter class - spritewidget library - Dart API</title>
  <!-- required because all the links are pseudo-absolute -->
  <base href="../..">

  <link href="https://fonts.googleapis.com/css?family=Source+Code+Pro:500,400i,400,300|Source+Sans+Pro:400,300,700" rel="stylesheet">
  <link rel="stylesheet" href="static-assets/github.css">
  <link rel="stylesheet" href="static-assets/styles.css">
  <link rel="icon" href="static-assets/favicon.png">

</head>

<body>

<div id="overlay-under-drawer"></div>

<header id="title">
  <button id="sidenav-left-toggle" type="button">&nbsp;</button>
  <ol class="breadcrumbs gt-separated dark hidden-xs">
    <li><a href="index.html">spritewidget</a></li>
    <li><a href="spritewidget/spritewidget-library.html">spritewidget</a></li>
    <li><a href="spritewidget/TexturedLinePainter-class.html">TexturedLinePainter</a></li>
    <li class="self-crumb">paint method</li>
  </ol>
  <div class="self-name">paint</div>
  <form class="search navbar-right" role="search">
    <input type="text" id="search-box" autocomplete="off" disabled class="form-control typeahead" placeholder="Loading search...">
  </form>
</header>

<main>

  <div class="col-xs-6 col-sm-3 col-md-2 sidebar sidebar-offcanvas-left">
    <h5>TexturedLinePainter class</h5>
    <ol>
      <li class="section-title"><a href="spritewidget/TexturedLinePainter-class.html#constructors">Constructors</a></li>
      <li><a href="spritewidget/TexturedLinePainter/TexturedLinePainter.html">TexturedLinePainter</a></li>
    
      <li class="section-title">
        <a href="spritewidget/TexturedLinePainter-class.html#instance-properties">Properties</a>
      </li>
      <li><a href="spritewidget/TexturedLinePainter/calculatedTextureStops.html">calculatedTextureStops</a></li>
      <li><a href="spritewidget/TexturedLinePainter/colors.html">colors</a></li>
      <li><a href="spritewidget/TexturedLinePainter/length.html">length</a></li>
      <li><a href="spritewidget/TexturedLinePainter/points.html">points</a></li>
      <li><a href="spritewidget/TexturedLinePainter/removeArtifacts.html">removeArtifacts</a></li>
      <li><a href="spritewidget/TexturedLinePainter/texture.html">texture</a></li>
      <li><a href="spritewidget/TexturedLinePainter/textureLoopLength.html">textureLoopLength</a></li>
      <li><a href="spritewidget/TexturedLinePainter/textureStopOffset.html">textureStopOffset</a></li>
      <li><a href="spritewidget/TexturedLinePainter/textureStops.html">textureStops</a></li>
      <li><a href="spritewidget/TexturedLinePainter/transferMode.html">transferMode</a></li>
      <li><a href="spritewidget/TexturedLinePainter/widths.html">widths</a></li>
      <li class="inherited"><a href="dart-core/Object/hashCode.html">hashCode</a></li>
      <li class="inherited"><a href="dart-core/Object/runtimeType.html">runtimeType</a></li>
    
      <li class="section-title"><a href="spritewidget/TexturedLinePainter-class.html#instance-methods">Methods</a></li>
      <li><a href="spritewidget/TexturedLinePainter/paint.html">paint</a></li>
      <li class="inherited"><a href="dart-core/Object/noSuchMethod.html">noSuchMethod</a></li>
      <li class="inherited"><a href="dart-core/Object/toString.html">toString</a></li>
    
      <li class="section-title inherited"><a href="spritewidget/TexturedLinePainter-class.html#operators">Operators</a></li>
      <li class="inherited"><a href="dart-core/Object/operator_equals.html">operator ==</a></li>
    
    
    
    </ol>
  </div><!--/.sidebar-offcanvas-->

  <div class="col-xs-12 col-sm-9 col-md-8 main-content">
    <h1>paint method</h1>

    <section class="multi-line-signature">
      <span class="returntype">void</span>
      <span class="name ">paint</span>
(<wbr><span class="parameter" id="paint-param-canvas"><span class="type-annotation"><a href="dart-ui/Canvas-class.html">Canvas</a></span> <span class="parameter-name">canvas</span></span>)
    </section>
    <section class="desc markdown">
      <p>Paints the line to the <code>canvas</code>.</p>
    </section>
    
    <section class="summary source-code" id="source">
      <h2><span>Implementation</span> </h2>
      <pre class="language-dart"><code class="language-dart">void paint(Canvas canvas) {
  &#47;&#47; Check input values
  assert(_points != null);
  if (_points.length &lt; 2) return;

  assert(_points.length == colors.length);
  assert(_points.length == widths.length);

  _cachedPaint.blendMode = transferMode;

  &#47;&#47; Calculate normals
  List&lt;Vector2&gt; vectors = &lt;Vector2&gt;[];
  for (Offset pt in _points) {
    vectors.add(new Vector2(pt.dx, pt.dy));
  }
  List&lt;Vector2&gt; miters = _computeMiterList(vectors, false);

  List&lt;Offset&gt; vertices = &lt;Offset&gt;[];
  List&lt;int&gt; indices = &lt;int&gt;[];
  List&lt;Color&gt; verticeColors = &lt;Color&gt;[];
  List&lt;Offset&gt; textureCoordinates;
  double textureTop;
  double textureBottom;
  List&lt;double&gt; stops;

  &#47;&#47; Add first point
  Offset lastPoint = _points[0];
  Vector2 lastMiter = miters[0];

  &#47;&#47; Add vertices and colors
  _addVerticesForPoint(vertices, lastPoint, lastMiter, widths[0]);
  verticeColors.add(colors[0]);
  verticeColors.add(colors[0]);

  if (texture != null) {
    assert(texture.rotated == false);

    &#47;&#47; Setup for calculating texture coordinates
    textureTop = texture.frame.top;
    textureBottom = texture.frame.bottom;
    textureCoordinates = &lt;Offset&gt;[];

    &#47;&#47; Use correct stops
    if (textureStops != null) {
      assert(_points.length == textureStops.length);
      stops = textureStops;
    } else {
      if (_calculatedTextureStops == null) _calculateTextureStops();
      stops = _calculatedTextureStops;
    }

    &#47;&#47; Texture coordinate points
    double xPos = _xPosForStop(stops[0]);
    textureCoordinates.add(new Offset(xPos, textureTop));
    textureCoordinates.add(new Offset(xPos, textureBottom));
  }

  &#47;&#47; Add the rest of the points
  for (int i = 1; i &lt; _points.length; i++) {
    &#47;&#47; Add vertices
    Offset currentPoint = _points[i];
    Vector2 currentMiter = miters[i];
    _addVerticesForPoint(vertices, currentPoint, currentMiter, widths[i]);

    &#47;&#47; Add references to the triangles
    int lastIndex0 = (i - 1) * 2;
    int lastIndex1 = (i - 1) * 2 + 1;
    int currentIndex0 = i * 2;
    int currentIndex1 = i * 2 + 1;
    indices.addAll(&lt;int&gt;[lastIndex0, lastIndex1, currentIndex0]);
    indices.addAll(&lt;int&gt;[lastIndex1, currentIndex1, currentIndex0]);

    &#47;&#47; Add colors
    verticeColors.add(colors[i]);
    verticeColors.add(colors[i]);

    if (texture != null) {
      &#47;&#47; Texture coordinate points
      double xPos = _xPosForStop(stops[i]);
      textureCoordinates.add(new Offset(xPos, textureTop));
      textureCoordinates.add(new Offset(xPos, textureBottom));
    }

    &#47;&#47; Update last values
    lastPoint = currentPoint;
    lastMiter = currentMiter;
  }

  &#47;&#47;TODO: Fix
&#47;&#47;    canvas.drawVertices(VertexMode.triangles, vertices, textureCoordinates, verticeColors, BlendMode.modulate, indices, _cachedPaint);
}</code></pre>
    </section>

  </div> <!-- /.main-content -->

  <div class="col-xs-6 col-sm-6 col-md-2 sidebar sidebar-offcanvas-right">
  </div><!--/.sidebar-offcanvas-->

</main>

<footer>
  <span class="no-break">
    spritewidget 0.9.16
  </span>

</footer>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="static-assets/typeahead.bundle.min.js"></script>
<script src="static-assets/highlight.pack.js"></script>
<script src="static-assets/URI.js"></script>
<script src="static-assets/script.js"></script>


</body>

</html>
